import { http } from "../plugin/request";

export const uploadFile = (
  file: FormData,
  callback: (e: ProgressEvent<EventTarget>) => void
) => http.upload(`/api/user/file`, file, callback, true);

export const findFile = (_id: string) =>
  http.setRequest("GET", `/api/user/findFile?_id=${_id}`);

export const existFile = (_id: string) =>
  http.setRequest("GET", `/api/user/fileExist?_id=${_id}`);

export const fileDelete = (_id: string) =>
  http.setRequest("DELETE", `/api/user/fileDelete?_id=${_id}`);

export const getFileFromA = (
  base64: string,
  name: string
) => {
  let dom = document.createElement("a");
  dom.download = name;
  dom.href = base64;
  document.body.appendChild(dom);
  dom.click();
  document.body.removeChild(dom);
};
